package com.amsp.oa.oademo.service.impl;

import com.amsp.oa.oademo.entity.MaintenanceForm;
import com.amsp.oa.oademo.mapper.MaintenanceFormMapper;
import com.amsp.oa.oademo.service.MaintenanceFormService;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

@Service
public class MaintenanceFormServiceImpl extends ServiceImpl<MaintenanceFormMapper, MaintenanceForm>
        implements MaintenanceFormService {

    @Override
    public IPage<MaintenanceForm> getPage(Integer current, Integer size, String applyDepartment, String applicant) {
        Page<MaintenanceForm> page = new Page<>(current, size);
        LambdaQueryWrapper<MaintenanceForm> wrapper = new LambdaQueryWrapper<>();

        if (StringUtils.hasText(applyDepartment)) {
            wrapper.like(MaintenanceForm::getApplyDepartment, applyDepartment);
        }

        if (StringUtils.hasText(applicant)) {
            wrapper.like(MaintenanceForm::getApplicant, applicant);
        }

        wrapper.orderByDesc(MaintenanceForm::getCreateTime);
        return page(page, wrapper);
    }
}